# Create your views here.
from django.shortcuts import render_to_response
from myuwaterloo.contact.forms import ContactForm
from django.core.mail import send_mail
from django.http import HttpResponseRedirect 
from django import forms as forms
from django.forms import ModelForm


def contact(request):

	user = request.user
	
	if request.method == 'POST':
		form = ContactForm(request.POST)
		if form.is_valid():
			topic = form.cleaned_data['topic']
			message = form.cleaned_data['message']
			sender = form.cleaned_data.get('sender', 'noreply@example.com')
			send_mail(
				'Feedback from myuwaterlooCourses: %s' % topic,
				message, sender,
				['swanson.steven@gmail.com']
			)
			return HttpResponseRedirect('/search/')
	else:
		form = ContactForm()
	return render_to_response('contact/contact.html', {'form': form, 'user':user})